package com.centriole.service.workflow.util;

import java.io.Serializable;

public class AjaxResult implements Serializable {

	private static final long serialVersionUID = 3819990384048045405L;
	 /**
     * 是否产生错误
     */
    public boolean isError;
    /**
     * 错误信息，或者成功信息
     */
    public String message;
    /**
     * 成功可能时返回的数据
     */
    public Object data;

    private AjaxResult() {
    }

    private AjaxResult(boolean error, String message, Object data) {
        isError = error;
        this.message = message;
        this.data = data;
    }

    public boolean isError() {
        return isError;
    }

    public void setError(boolean error) {
        isError = error;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static AjaxResult Error() {
        return new AjaxResult(true, "", null);
    }

    public static AjaxResult Error(String message) {
        return new AjaxResult(true, message, null);
    }

    public static AjaxResult Success() {
        return new AjaxResult(false, "", null);
    }

    public static AjaxResult Success(String message) {
        return new AjaxResult(false, message, null);
    }

    public static AjaxResult Success(String message, Object data) {
        return new AjaxResult(false, message, data);
    }

    @Override
    public String toString() {
        try {
            return JSONHelper.toJson(this);
        } catch (Exception e) {
            return "";
        }
    }
}
